﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SSharp.Core.DataTypes;

namespace SSharp.Core.Evaluator {
	public static partial class Eval {
		private class LambdaEvaluator : SpecialFormEvaluator {
			public LambdaEvaluator() : base("lambda") { }

			/// <summary>
			/// Allows to duplicate this with a different symbol, e.g. ƛ
			/// </summary>
			public LambdaEvaluator(string specialSymbol) : base(specialSymbol) { }

			public override EvaluationResult Evaluate(object[] parameters, IEnvironment env) {
				if (parameters.Length < 2) {
					throw new SyntaxError("Lambda: Requires at least a parameter list and one action");
				}

				object lambdaParameters = parameters[0];
				object body = new Cons(new Symbol("begin"), List.Create(parameters.Skip(1)));

				return new EvaluationResult(new CompoundProcedure(env,
					"lambda",
					lambdaParameters,
					body));
			}
		}
	}
}
